from fpdf import FPDF
from PIL import Image
import os

from PIL import Image
import os

def combine2Pdf( folderPath, pdfFilePath ):
    files = os.listdir( folderPath )
    pngFiles = []
    sources = []
    #多少张图片
    for file in range(0,272):
        pngFiles.append( folderPath + str(file) + ".png" )
    print(pngFiles)

    output = Image.open( pngFiles[0] )
    pngFiles.pop( 0 )
    print(pngFiles)
    for file in pngFiles:
        pngFile = Image.open( file )
        if pngFile.mode == "RGB":
            pngFile = pngFile.convert( "RGB" )
        sources.append( pngFile )
    output.save( pdfFilePath, "pdf", save_all=True, append_images=sources )

if __name__ == "__main__":
    folder = r"D:/Temp/png/"
    pdfFile = "python.pdf"
    combine2Pdf( folder, pdfFile )